#!/bin/bash
#
# Implements the lzma compression method
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 17 November 2013
#
#   Copyright 2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#


## pcomp_supported_lzma
##
## Returns 0 if the xz(1) command is available on the system. Otherwise,
## returns non-zero.
##
function pcomp_supported_lzma() {
	is_callable xz
	return $?
}


## pcomp_compress_lzma <input file> <output file>
##
## Compresses the <input file> using xz(1), saving the output to
## <output file>. Returns 0 if successful, non-zero if an error occurs.
##
function pcomp_compress_lzma() {
	xz -F lzma -c -z "$1" > "$2"
	return $?
}


## pcomp_decompress_lzma <input file> <output file>
##
## Decompresses the <input file> using xz(1), saving the output to
## <output file>. Returns 0 if successful, non-zero if an error occurs.
##
function pcomp_decompress_lzma() {
	xz -F lzma -c -d "$1" > "$2"
	return $?
}
